package com.example.enginsdk;


import org.greenrobot.eventbus.EventBus;

/**
 * 应用启动做一些启动相关的初始化操作
 * User:Gaolei  gurecn@gmail.com
 * Date:2016/10/10
 * I'm glad to share my knowledge with you all.
 */
public class LauncherModel {

    private volatile EventBus mGlobalEventBus;

    private LauncherModel() {
    }

    /**
     * 获取实例<br>
     */
    public static LauncherModel getInstance() {
        return Holder.INSTANCE;
    }

    /**
     * 获取一个全局的EventBus实例<br>
     */
    public EventBus getGlobalEventBus() {
        if (mGlobalEventBus == null) {
            synchronized (this) {
                if (mGlobalEventBus == null) {
                    EventBus.builder().installDefaultEventBus();
                    mGlobalEventBus = EventBus.getDefault();
                }
            }
        }

        return mGlobalEventBus;
    }

    /**
     * 使用全局EventBus post一个事件<br>
     */
    public void postEvent(Object event) {
        getGlobalEventBus().post(event);
    }

    private static class Holder {
        private static final LauncherModel INSTANCE = new LauncherModel();
    }
}
